package code19_jdk8.stream;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class Test01 {

	public static void main(String[] args) {
		// Stream对象的获取
		List<String> list = Arrays.asList("aa","bb","cc");
		// 1.stream() 获取的是串行流
		Stream<String> stream = list.stream();
		// 2.parallelStream() 获取的是并行流
		Stream<String> parallelStream = list.parallelStream();
		
		// 3.
		String[] arr = {"aa","bb","cc"};
		Stream<String> stream2 = Arrays.stream(arr);
		
		// 4.
		String[] arr2 = {"aa","bb","cc"};
		Stream<String> stream3 = Stream.of(arr2);
		Stream<String> stream4 = Stream.of("aa","bb","cc");
		
		// 惰性求值
		List<Emp> data = Emp.getData();
		data.stream()
			.limit(4)
			.filter( e -> {
				System.out.println("中间操作:"+e);
				return true;
			});
		System.out.println("over");
		data.stream()
			.limit(4)
			.filter( e -> {
				System.out.println("中间操作:"+e);
				return true;
			})
			// 内部迭代-终止操作
			.forEach( e -> System.out.println("forEach:" + e) );
		System.out.println("over");
		
		
	}
	
}
